﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Xml;
using System.Xml.Serialization;
using Commons;

namespace SimpComm
{
    public static class MyTool
    {
        public static string GetIP(this Controller ctrl)
        {
            string ip;
            if (ctrl.HttpContext.Request.ServerVariables["HTTP_VIA"] != null)
            {
                ip = ctrl.HttpContext.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
            }
            else
            {
                ip = ctrl.HttpContext.Request.ServerVariables["REMOTE_ADDR"].ToString();
            }
            return ip;
        }

        public static string GetColes(string o)
        {
            string random = Randoms.GetRandomChars(12);
            return random;
        }

        public static string GetShotrString(this string left, int limit_num)
        {
            if (left.Length > limit_num)
                return left.Substring(0, limit_num) + "...";
            return left;
        }

        public static bool IsN(this  string str)
        {
            return string.IsNullOrWhiteSpace(str);
        }
        public static bool NotN(this  string str)
        {
            return !string.IsNullOrWhiteSpace(str);
        }

    }
}
